// packageStore/pages/purchase/photorecords/index.js
import BasePage from '../../../../js/common/base-page'
import {api} from '../../../../js/util'
import {orderlist, fastorder} from "../../../../js/modules/order.js"
var app = getApp();
BasePage({
  pageKey:"photoRecords",
  /**
   * 页面的初始数据
   */
  data: {
    imgDomain: api.imgDomain,
    enableOss: api.enableOss,
    list:[],
    PageSize:10,
    PageIndex:1,
    hasMoreData: true,
    isLoadComplete: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadList();
  },
  /**
   * 获取拍照下单记录
   */
  loadList:function(){
    let that = this;
    let {PageIndex,PageSize} = that.data;
    let data = {
      PageIndex:PageIndex,
      PageSize:PageSize
    }
    fastorder.loadPhotoRecords(data,function(res){
      let hasMore = res.count > PageIndex * PageSize;
      var data = res.data;
      data.map(item=>{
        item.Photos = item.Photos.split(',');
        //组装月份分组信息
        let time = item.AddTime.split('/').filter((ele,idx,arr)=>{return arr.length-1 !==idx});
        item.group = time.join('-')
      })
      //当分页大于1时，累加
      if (PageIndex > 1) {
        data = that.data.list.concat(data);
      }
      //如果key为变量作为key值的时候要用[]包裹起来
      that.setData({
        list: data,
        hasMoreData: hasMore,
        isLoadComplete: true
      });
    })
  },
  /**
   * 查看大图
   */
  showBigImg:function(event){
    var src = event.currentTarget.dataset.src;//获取data-src
    var imgList = event.currentTarget.dataset.list;//获取data-list
    var imgSrl=[];
    for (var i = 0; i < imgList.length;i++){
      imgSrl[i] = this.data.imgDomain+imgList[i];
    }
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgSrl // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    this.setData({
      PageIndex: 1,
      isLoadComplete: false
    })
    this.loadList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.hasMoreData) {
      var index = this.data.PageIndex;
      this.setData({
        PageIndex:index+1
      },function(){
        this.loadList();
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})